package com.woniuxy.hrp.mapper;

import com.woniuxy.hrp.entity.Doctor;
import com.woniuxy.hrp.entity.Position;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @program: hrph
 * @InterfaceName PositionMapper
 * @description:医生职位DAO
 * @author: shanshanfan
 * @create: 2022-08-29 09:00
 * @Version 1.0
 **/

public interface PositionMapper {

    /***
     * @description: 增：职位增加
     * @param: position
     * @return: void
     * @author shanshanfan
     * @date: 2022/8/29 09:02
     */
    @Insert("insert into hrp_position(title,fee) values(#{title},#{fee})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void add(Position position);

    /***
     * @description: 删：根据id删除职位
     * @param: id
     * @return: void
     * @author shanshanfan
     * @date: 2022/8/29 09:10
     */
    @Delete("delete from hrp_position where id=#{id}")
    void delete(int id);


    /***
     * @description: 改：修改指定id的职称的费用
     * @param: id
     * @return: void
     * @author shanshanfan
     * @date: 2022/8/29 09:15
     */
    @Update("update hrp_position set fee=#{fee} where id=#{id}")
    void update(int id);

    /***
     * @description: 查：按id查找职位信息（职称和挂号费）
     * @param: id
     * @return: com.woniuxy.hrp.entity.Position
     * @author shanshanfan
     * @date: 2022/8/29 09:30
     */
    @Select("select * from hrp_position where id=#{id}")
    Position getById(int id);

    /***
     * @description: 查：多条件查询职位数据（集合）
     * @param: position
     * @return: 符合查询条件的职位集合
     * @author shanshanfan
     * @date: 2022/8/29 09:42
     */
    @SelectProvider(type = SqlProvider.class, method = "selectPositionByCondition")
    List<Position> selectByCondition(Position position);

    /***
     * @description: 用于产生动态查询、修改的sql语句
     * @author shanshanfan
     * @date: 2022/8/29 09:25
     */
    public static class SqlProvider{

        public static String selectPositionByCondition(Position position) {
            String sql = new SQL() {
                {
                    SELECT("*");
                    FROM("hrp_position");
                    if (position.getTitle()!= null) {
                        WHERE("title=#{title}");
                    }
                    if (position.getFee()!= null) {
                        WHERE("fee=#{fee}");
                    }
                }}.toString();
            return sql;
        }
    }

}
